<template>
  <a-modal
    :title="title"
    :width="800"
    :visible="visible"
    :okButtonProps="{ props: {disabled: disableSubmit} }"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

    <!--    <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="订阅id"
          :hidden="hiding"
          hasFeedback>
          <a-input placeholder="请输入订阅id" v-decorator="['fdSscid', {'initialValue':this.mainId}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="表id"
          hasFeedback>
          <a-input placeholder="请输入表id" v-decorator="['fdTableId', validatorRules.fdTableId ]" />
        </a-form-item>-->
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="表名称"
          hasFeedback>
          <a-input placeholder="请输入表名称" v-decorator="['fdTableId_dictText', {}]" readonly = "readonly" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="是否脱敏"
          hasFeedback>
          <j-dict-select-tag placeholder="请输入是否脱敏"  v-decorator="['fdDes', {}]" :triggerChange="true" dictCode="autossc_release"/>
        </a-form-item>

        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="自定义条件"
          hasFeedback>
          <a-textarea :rows="5" placeholder="请输入自定义条件" v-decorator="[ 'fdWhere', {} ]" />
        </a-form-item>

        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="状态"
          hasFeedback>
          <j-dict-select-tag placeholder="请输入状态"  v-decorator="['fdStatus', {}]" :triggerChange="true" dictCode="hadoop_hdflag"/>

        </a-form-item>

        <!--<a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="是否发布到调度平台"
          hasFeedback>
          <j-dict-select-tag placeholder="请输入是否发布到调度平台"  v-decorator="['fdRelease', {}]" :triggerChange="true" dictCode="autossc_release"/>
        </a-form-item>-->

      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
  import {httpAction} from '@/api/manage'
  import pick from 'lodash.pick'
  import moment from 'moment'
  import JDate from '@/components/jeecg/JDate'

  export default {
    components: {
      JDate
    },
    name: 'OpersscTabdetailModal',
    data() {
      return {
        title: '操作',
        visible: false,
        model: {},
        labelCol: {
          xs: {span: 24},
          sm: {span: 5}
        },
        wrapperCol: {
          xs: {span: 24},
          sm: {span: 16}
        },
        moment,
        format: 'YYYY-MM-DD HH:mm:ss',
        disableSubmit: false,
        mainId: '',
        hiding: false,
        confirmLoading: false,
        form: this.$form.createForm(this),
        validatorRules: {
          fdDes: { rules: [{ required: true, message: '请输入是否脱敏!' }] },
          fdTableId: { rules: [{ required: true, message: '请输入表id!' }] },
          fdWhere: { rules: [{ required: true, message: '请输入自定义条件!' }] },
          fdStatus: { rules: [{ required: true, message: '请输入状态!' }] },
          fdRelease: { rules: [{ required: true, message: '请输入是否发布到调度平台!' }] },
          createUser: { rules: [{ required: true, message: '请输入创建人!' }] },
          updateUser: { rules: [{ required: true, message: '请输入修改人!' }] },
          isDelete: { rules: [{ required: true, message: '请输入是否删除!' }] },
        },
        url: {
          add: '/rule/opersscTpReview/addOpersscTabdetail',
          edit: '/rule/opersscTpReview/editOpersscTabdetail'
        }
      }
    },
    created() {
    },
    methods: {
      add(mainId) {
        if (mainId) {
          this.edit({mainId}, '')
        } else {
          this.$message.warning('请选择一条数据')
        }
      },
      detail(record) {
        this.edit(record, 'd')
      },
      edit(record, v) {
        if (v == 'e') {
          this.hiding = false;
          this.disableSubmit = false;
        } else if (v == 'd') {
          this.hiding = false;
          this.disableSubmit = true;
        } else {
          this.hiding = true;
          this.disableSubmit = false;
        }
        this.form.resetFields();
        this.mainId = record.mainId;
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model, 'fdSscid', 'fdDes', 'fdTableId','fdTableId_dictText', 'fdWhere', 'fdStatus', 'fdRelease', 'createUser', 'updateUser', 'isDelete', ))
          // 时间格式化
        })
      },
      close() {
        this.$emit('close');
        this.visible = false;
      },
      handleOk() {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if (!this.model.id) {
              httpurl += this.url.add;
              method = 'post';
            } else {
              httpurl += this.url.edit;
              method = 'put';
            }
            let formData = Object.assign(this.model, values);
            //时间格式化
            httpAction(httpurl, formData, method).then((res) => {
              if (res.success) {
                that.$message.success(res.message);
                that.$emit('ok');
              } else {
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }
        })
      },
      handleCancel() {
        this.close();
      }
    }
  }
</script>

<style scoped>

</style>
